package com.sun.lib.net.remote;

import android.graphics.Bitmap;

import com.lzy.okgo.model.Response;
import com.sun.lib.LibCommonManager;
import com.sun.lib.util.SystemUtil;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2019/3/23.
 * <p>
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */
public abstract class BitmapObserver implements Observer<Response<Bitmap>> {
    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(Response<Bitmap> stringResponse) {
        Bitmap bitmap = stringResponse.body();
        onSuccess(bitmap);
    }

    @Override
    public void onError(Throwable e) {
        onFailed(e);
    }

    @Override
    public void onComplete() {

    }

    public abstract void onSuccess(Bitmap bitmap);

    protected void onFailed(Throwable e) {
        if (!SystemUtil.isNetWorkConnected(LibCommonManager.getInstance().getContext())) {
            LibCommonManager.showToast("网络异常");
        } else {
            //httpListener.onHttpFailure("数据获取异常");
            LibCommonManager.showToast("图片获取失败");
        }
    }
}
